﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using Itop.YHPC.Model;
using System.Collections.Generic;
using Itop.YHPC.controller;

namespace Itop.YHPC.search
{
    public partial class search_ajax : AjaxPage<yhpcMain>
    {
        protected override IList<yhpcMain> onRead()
        {
            string fxrq1 = Request.QueryString["fxrq1"];
            int page = int.Parse(Request.QueryString["page"]);
            int limit = int.Parse(Request.QueryString["limit"]);
            IList<yhpcMain> list = new List<yhpcMain>();
            if (fxrq1 != "100")
            {
                string yhjt = Request.QueryString["yhjt"];
                string zt = Request.QueryString["zt"];
                string pgdj = Request.QueryString["pgdj"];
                string fxrq2 = Request.QueryString["fxrq2"];
                string yhszdw = Request.QueryString["yhszdw"];
                string fxrdw = Request.QueryString["fxrdw"];
                string yhbh = Request.QueryString["yhbh"];
                string yhly = Request.QueryString["yhly"];
                string gsbm = Request.QueryString["gsbm"];
                string sfxc = Request.QueryString["sfxc"];
                string yhzyfl = Request.QueryString["yhzyfl"];
                string ypgdj = Request.QueryString["ypgdj"];
                StringBuilder sbulder = new StringBuilder();
                sbulder.Append(" where 1=1 ");
                if (zt != "" && zt != "全部")
                    sbulder.Append(" and lcstatus='" + zt + "'");
                if (ypgdj != "" && ypgdj != "全部")
                    sbulder.Append(" and ypgdj='" + ypgdj + "'");
                if (pgdj != "" && pgdj != "全部")
                    sbulder.Append(" and pgdj='" + pgdj + "'");
                if (fxrq1 != "")
                    sbulder.Append(" and fxrq>='" + fxrq1 + "'");
                if (fxrq2 != "")
                    sbulder.Append(" and fxrq<='" + fxrq2 + "'");
                if (yhly != "" && yhly != "全部")
                    sbulder.Append(" and yhly='" + yhly + "'");
                if (gsbm != "" && gsbm != "全部")
                    sbulder.Append(" and gsbm='" + gsbm + "'");
                if (yhzyfl != "" && yhzyfl != "全部")
                    sbulder.Append(" and yhzyfl='" + yhzyfl + "'");
                if (sfxc != "" && sfxc != "全部")
                    sbulder.Append(" and yssfxc='"+sfxc+"'");
                if (yhjt != "")
                    sbulder.Append(" and yhjt like '%" + yhjt + "%'");
                if (yhszdw != "")
                    sbulder.Append(" and yhdw like '%" + yhszdw + "%'");
                if (fxrdw != "")
                    sbulder.Append(" and fxrdw like '%" + fxrdw + "%'");
                if (yhbh != "")
                    sbulder.Append(" and yhbh like '%" + yhbh + "%'");
                sbulder.Append(" order by fxrq desc");
                 list = workflowController.GetMainList(sbulder.ToString());

            }
            else
            {
             
                StringBuilder sbulder = new StringBuilder();
                sbulder.Append(" where 1=1 ");
                sbulder.Append(" order by fxrq desc");
                list = workflowController.GetMainList(sbulder.ToString());
            }
            total = list.Count;
            return GetPageList(page,list,limit);
        }
        int total = 0;
        protected override int GetTotal()
        {
            return total;
        }

        public IList<yhpcMain> GetPageList(int page, IList<yhpcMain> list, int limit)
        {
            IList<yhpcMain> temp = new List<yhpcMain>();
            for (int i = (page - 1) * limit; i < ((page * limit) > list.Count ? list.Count : (page * limit)); i++)
            {
                temp.Add(list[i]);
            }
            return temp;
        }
        public string GetUserName()
        {
            string name = "";
            try
            {
                name = BasePage.GetUser().UserName;
            }
            catch { }
            return name;
        }
        protected override bool onDelete(IList<yhpcMain> list)
        {
            foreach (yhpcMain yhpc in list)
            {
                workflowController.Delete(yhpc);
            }
            return true;
        }
    }
}
